import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;


public class Square extends JPanel{
	
	private int x = 0;
	private int y = 0;
	private int width = 100;
	private int height = 100;
	private Color myColor = new Color(0,0,0);
	private boolean clicked = false;
	private boolean pl = false;

	private ImageIcon xIcon = new ImageIcon(getClass().getResource("x.png"));
	private ImageIcon oIcon = new ImageIcon(getClass().getResource("o.png"));
	private Image icon;


	public Square(int xVal, int yVal) {
		x = xVal;
		y = yVal;
		icon = xIcon.getImage();
	}
	
	public void Player1() {
		icon = xIcon.getImage();
	}
	
	public void Player2() {
		icon = oIcon.getImage();
	}
	
	public boolean player() {
		return pl;
	}
	
	public void reset() {
		myColor = new Color(0,0,0);
		clicked = false;
		pl = false;
	}
	
	public boolean Change (int count) {
		if (count % 2 == 1 && clicked == false) {
			Player1();
			pl = true;
			clicked = true;
			return true;
		}
		
		if (count % 2 == 0 && clicked == false) {
			Player2();
			pl = false;
			clicked = true;
			return true;
		}
		
		return false;
		
	}
	
	public void paint(Graphics g) {
		
		if (clicked == false) {
			g.setColor(myColor);
			g.fillRect(x, y, width, height);
		}
		else
			g.drawImage(icon, x, y, this);
	}
}		
